var app = getApp()
Page({
  data: {
    youhuiquan: [],
  },
  lijilingqu(e) {
    var t = this,
      s = t.data.youhuiquan,
      yh_id = e.currentTarget.dataset.yh_id,
      i = e.currentTarget.dataset.dex;

    //查询我是否领取过
    app.util.request({
      'url': "entry/wxapp/Allyouhuiquan",
      data: {
        op: 'lingqu',
        yh_id: yh_id,
        openid: wx.getStorageSync('openid'),
      },
      header: {
        'content-type': 'application/json'
      },
      success: function(res) {
        console.log(res)
        if (res.data == 0) {
          wx.showToast({
            title: '每人限制领取1次',
            icon: "none",
            duration: 2e3
          })
        } else {
          wx.showToast({
            title: '领取成功',
            icon: "none",
            duration: 2e3
          })
        }

      },
      fail: function(err) {
        console.log(err)
      },
    })
    t.setData({
      youhuiquan: s
    })

    setTimeout(function() {
      wx.navigateBack({})
    }, 1000)
  },
  onLoad: function(n) {
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
  },
  onReady: function() {
    this.getAllyouhuiquan()
  },
  onShow: function() {},
  onHide: function() {},
  onUnload: function() {},
  getAllyouhuiquan: function(res) {
    var that = this
    app.util.request({
      'url': "entry/wxapp/Allyouhuiquan",
      data: {
        op: 'youhuilist'
      },
      header: {
        'content-type': 'application/json'
      },
      success: function(res) {
        console.log(res)
        that.setData({
          youhuiquan: res.data
        })
      },
      fail: function(err) {
        console.log(err)
      },
    })
  }
});